/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byzantine.views;

import byzantine.ByzantineModel;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author rpathan
 */
public class LegendView extends JPanel implements View {

    private static final String previousString = "Previous";
    private static final String pathString = "Path";
    private static final String currentString = "Current";
    private static final Font font = new Font("Dialog", Font.BOLD, 11);

    //private int width;
    //private int height;
    //private int labelSpacing;

    private int width = 250;
    private int height = 85;
    private int labelSpacing = 1;

    ByzantineModel model;
    private JPanel legendPanel;
    private JLabel panelName;
    private JLabel previousLabel;
    private JLabel pathLabel;
    private JLabel currentLabel;
    private JPanel previousColorLabel;
    private JPanel pathColorLabel;
    private JPanel currentColorLabel;
    

    public LegendView(ByzantineModel model) {
        this.model = model;
        model.addObserver(this);
/*
        Toolkit t = Toolkit.getDefaultToolkit();
        Dimension screenSize = t.getScreenSize();
        width = (int)((screenSize.width - 10) * 0.185);
        height = (int)((screenSize.height - 100) * 0.138);
        labelSpacing = (int)(height * 0.2);
*/
        initializeView();
    }

    private void initializeView() {

        panelName = new JLabel("Legend");
        panelName.setAlignmentX(Component.CENTER_ALIGNMENT);
        panelName.setAlignmentY(Component.CENTER_ALIGNMENT);
        panelName.setFont(font);

        previousLabel = new JLabel(previousString);
        previousLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        previousLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        previousLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        previousLabel.setFont(font);

        previousColorLabel = new JPanel();
        previousColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        previousColorLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        previousColorLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        previousColorLabel.setBackground(Color.GREEN);
        previousColorLabel.setFont(font);

        pathLabel = new JLabel(pathString);
        pathLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        pathLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        pathLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        pathLabel.setFont(font);

        pathColorLabel = new JPanel();
        pathColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        pathColorLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        pathColorLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        pathColorLabel.setBackground(Color.GREEN);
        pathColorLabel.setFont(font);

        currentLabel = new JLabel(currentString);
        currentLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        currentLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        currentLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        currentLabel.setFont(font);

        currentColorLabel = new JPanel();
        currentColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        currentColorLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        currentColorLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
        currentColorLabel.setBackground(Color.RED);
        currentColorLabel.setFont(font);

        legendPanel = new JPanel(new GridLayout(3, 2));
        legendPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        legendPanel.add(previousLabel);
        legendPanel.add(previousColorLabel);
        legendPanel.add(pathLabel);
        legendPanel.add(pathColorLabel);
        legendPanel.add(currentLabel);
        legendPanel.add(currentColorLabel);

        Box box1 = Box.createVerticalBox();
        box1.setAlignmentX(Component.CENTER_ALIGNMENT);
        box1.setAlignmentY(Component.CENTER_ALIGNMENT);
        box1.add(panelName);
        box1.add(Box.createVerticalStrut(labelSpacing));
        box1.add(legendPanel);

        this.add(box1);

        setBorder(BorderFactory.createEtchedBorder());
    }

    public void valueChanged() {
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(width, height);
    }
}
